import tui from '../../../common/httpRequest'
Page({
  data: {
    list: [],
    listOnline: [
      {
        id: 'basic',
        name: '基础组件',
        open: false,
        pages: [
          {
            name: '基础组件',
            page: '/pages/index/basic/basic'
          }
        ]
      },
      {
        id: 'map',
        name: '地图',
        open: false,
        pages: [
          {
            name: '拖拽定位',
            page: '/pages/index/location/location'
          },
          {
            name: '周边兴趣点',
            page: '/pages/index/maps/maps'
          },
          {
            name: '地址解析',
            page: '/pages/index/longlat/longlat'
          },
          {
            name: '天气',
            page: '/pages/index/weather/weather'
          }
        ]
      },
      {
        id: 'index',
        name: '索引列表',
        open: false,
        pages: [
          {
            name: '城市选择',
            page: '/pages/index/selectCity/selectCity'
          },
          {
            name: '索引列表',
            page: '/pages/index/indexList/indexList'
          },
          {
            name: '索引&吸顶效果',
            page: '/pages/template/chat/contacts/contacts'
          }
        ]
      },
      {
        id: 'nav',
        name: '三级联动',
        open: false,
        pages: [
          {
            name: 'picker三级联动',
            page: '/pages/index/picker/picker'
          },
          {
            name: 'picker-view三级联动',
            page: '/pages/index/picker-view/picker-view'
          }
        ]
      },
      {
        id: 'canvas',
        name: '二维码生成',
        open: false,
        pages: [
          {
            name: '二维码生成',
            page: '/pages/index/qrcode/qrcode'
          }
        ]
      },
      {
        id: 'drawer',
        name: 'drawer抽屉',
        open: false,
        pages: [
          {
            name: 'drawer抽屉',
            page: '/pages/index/drawer/drawer'
          }
        ]
      },
      {
        id: 'swipe',
        name: '滑动菜单',
        open: false,
        pages: [
          {
            name: '滑动菜单',
            page: '/pages/index/swipe-action/swipe-action'
          }
        ]
      },
      {
        id: 'class',
        name: '分类菜单',
        open: false,
        pages: [
          {
            name: '顶部选项卡',
            page: '/pages/index/navbar/navbar'
          },
          {
            name: '垂直分类',
            page: '/pages/template/mall/classify/classify'
          },
          {
            name: '垂直分类联动',
            page: '/pages/index/classify/classify'
          }
        ]
      },
      {
        id: 'refresh',
        name: '上拉加载下拉刷新',
        open: false,
        pages: [
          {
            name: '新闻列表',
            page: '/pages/index/news/news'
          },
          {
            name: '商品列表',
            page: '/pages/index/product/product'
          }
        ]
      },
      {
        id: 'template',
        name: '模板',
        open: false,
        pages: [
          {
            name: '商城模板',
            page: '/pages/template/mall/mall/mall'
          },
          {
            name: '新闻模板',
            page: '/pages/template/news/index/index'
          },
          {
            name: '聊天模板',
            page: '/pages/template/chat/msgList/msgList'
          },
          {
            name: '登录模板',
            page: '/pages/template/login/login/login'
          },
          {
            name: '签到模板',
            page: '/pages/extend/template/template'
          },
          {
            name: '多语言模板',
            page: '/pages/extend/template/template'
          }
        ]
      }
    ]

  },

  onLoad: function (options) {
    let list = [...this.data.listOnline]
    this.setData({
      list: list.splice(0, 7)
    })
    setTimeout(() => {
      tui.request("/Home/GetStatus", "GET", {}, false, true, true).then((res) => {
        if (res.code == 100 && res.data == 1) {
          getApp().globalData.isOnline = true
          this.setData({
            list: this.data.listOnline
          })
        }
      }).catch((res) => { 

      })
    }, 50)


    // 在页面中定义插屏广告
    let interstitialAd = null

    // 在页面onLoad回调事件中创建插屏广告实例
    if (wx.createInterstitialAd) {
      interstitialAd = wx.createInterstitialAd({
        adUnitId: 'adunit-44bbe9a9087910e3'
      })
      interstitialAd.onLoad(() => { })
      interstitialAd.onError((err) => { })
      interstitialAd.onClose(() => { })
    }

    // 在适合的场景显示插屏广告
    if (interstitialAd) {
      interstitialAd.show().catch((err) => {
        console.error(err)
      })
    }
  },
  kindToggle: function (e) {
    var id = e.currentTarget.id,
      list = this.data.list;
    for (var i = 0, len = list.length; i < len; ++i) {
      if (list[i].id == id) {
        list[i].open = !list[i].open
      } else {
        list[i].open = false
      }
    }
    this.setData({
      list: list
    });
  },
  emit(city) {
    setTimeout(() => {
      tui.toast('您选择了：' + city);
    }, 350)
  },
  subway() {
      let plugin = requirePlugin("subway");
      let key = 'ZEHBZ-UK5K4-CN5UN-XX4YM-4LS66-IEFWH';
      let referer = 'ThorUI';
      wx.navigateTo({
        url: 'plugin://subway/index?key=' + key + '&referer=' + referer
      });
  },
  github: function () {
    tui.copy('https://github.com/dingyong0214/ThorUI', "链接已复制")
  },
  template: function () {
    wx.navigateTo({
      url: '../extend-view/template/template'
    })
  },
  doc: function () {
    wx.removeTabBarBadge({
      index: 0
    })
    wx.navigateTo({
      url: '../../doc/doc/doc'
    })
  },
  openThorUI() {
    wx.navigateToMiniProgram({
      appId: 'wxd3c1da92cb8fcf40'
    });
  },
  onShareAppMessage: function () {
    return {
      title: "ThorUI组件库"
    }
  }
})